package com.gxa.controller;

import com.gxa.pojo.Current;
import com.gxa.pojo.Familyhistory;
import com.gxa.service.CurrentService;
import com.gxa.service.FamilyhistoryService;
import com.gxa.util.JsonResult;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.security.PrivateKey;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/familyhistory")
//已经测试通过
public class FamilyhistoryController {
    @Resource
    private  FamilyhistoryService familyhistoryService=null;
    @PostMapping("/findById")
    @ResponseBody
    public Map findById( @RequestBody Map<String,String> map){
        Integer id = Integer.valueOf(map.get("id"));
        JsonResult jsonResult = new JsonResult();
        if(id==null||id.equals("")){
            jsonResult.setMsg("id不能为空");
            return jsonResult.getValues();
        }
        Familyhistory byId = familyhistoryService.findById(id);
        jsonResult.setData(byId);
        return jsonResult.getValues();
    }
@PostMapping("/update")
@ResponseBody
    public  Map update(@RequestBody Familyhistory familyhistory){
        boolean update =familyhistoryService.update(familyhistory);
        JsonResult jsonResult = new JsonResult();
        if(update!=true){
            jsonResult.setCode("203");
            jsonResult.setMsg("修改失败");
            return jsonResult.getValues();
        }
        jsonResult.setCode("201");
        jsonResult.setMsg("修改成功");
        return jsonResult.getValues();
    }
    @Resource
    private CurrentService currentService=null;
    //查寻所有的家族史现病史
    @PostMapping("/find")
    @ResponseBody
    public Map find(@RequestBody Map<String,String> stringMap){

        Integer id = Integer.valueOf(stringMap.get("id"));
        JsonResult jsonResult = new JsonResult();
        Map<String,Object> map = new HashMap<String,Object>();
        if(id!=null||!id.equals("")){

            Current byId2 = currentService.findById2(id);
            Familyhistory byId = familyhistoryService.findById(id);
            jsonResult.setCode("200");
            map.put("aa",byId);
            map.put("bb",byId2);
            jsonResult.setData(map);
            return  jsonResult.getValues();
        }
        jsonResult.setCode("208");
        jsonResult.setMsg("id不能为空");
        return  jsonResult.getValues();
    }


    }


